local skel = fk.CreateSkill {
  name = "emo__zhiai",
}

Fk:loadTranslationTable{
  ["emo__zhiai"] = "挚爱",
  [":emo__zhiai"] = "每轮限一次，当一名其他角色受到致死伤害时，你可以令该伤害转移至你，然后你可以使用一张牌。",

  ["#emo__zhiai-invoke"] = "挚爱：你可以将 %dest 即将受到的 %arg 点伤害转移给你",
  ["#emo__zhiai-use"] = "挚爱：你可以使用一张牌",
}

skel:addEffect(fk.DamageInflicted, {
  anim_type = "support",
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryRound)
  end,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target ~= player and player:usedSkillTimes(skel.name, Player.HistoryRound) == 0
    and (data.damage >= (target.shield + target.hp) )
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__zhiai-invoke::"..target.id..":"..data.damage  }) then
      event:setCostData(self, { tos = {target} })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local n = data.damage
    data:preventDamage()
    if not player.dead then
      room:damage{
        from = data.from,
        to = player,
        damage = n,
        damageType = data.damageType,
        skillName = data.skillName,
        chain = data.chain,
        card = data.card,
      }
    end
  end,
})

return skel
